
using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using bjeschool_csharp.Model;

namespace bjeschool
{
	public partial class LeftTabController : UIViewController
	{
		private UIView currShowView;

		[Outlet("MMGroup_Teacher_View")]
		private UIView MMGroup_Teacher_View {get;set;}

		[Outlet("MMGroup_Parent_View")]
		private UIView MMGroup_Parent_View {get;set;}

		[Outlet("MMGroup_Student_View")]
		private UIView MMGroup_Student_View {get;set;}

		[Outlet("MM_HomeSchoolParent_View")]
		private UIView MM_HomeSchoolParent_View {get;set;}

		[Outlet("MM_MyClassStudent_View")]
		private UIView MM_MyClassStudent_View {get;set;}

		[Outlet("MM_FirstPage_View")]
		private UIView MM_FirstPage_View {get;set;}

		[Outlet("MM_MyClass_View")]
		private UIView MM_MyClass_View {get;set;}
		
		[Outlet("MM_MyCourse_View")]
		private UIView MM_MyCourse_View {get;set;}
		
		[Outlet("MM_HomeScool_View")]
		private UIView MM_HomeScool_View {get;set;}
		
		[Outlet("MM_Personnal_View")]
		private UIView MM_Personnal_View {get;set;}
		
		[Outlet("MM_SyncClass_View")]
		private UIView MM_SyncClass_View {get;set;}

		[Action("On_MM_FirstPage_Click")]
		void On_MM_FirstPage_Click ()
		{
			if(AppDelegate.loginuser is M_Teacher)
				AppDelegate.app.Window.RootViewController = new FirstPageController("FirstPageController");
			else if(AppDelegate.loginuser is M_Parent)
				AppDelegate.app.Window.RootViewController = new FirstPageController("FirstPageParent");
			else
				AppDelegate.app.Window.RootViewController = new FirstPageController("FirstPageStudent");

		}

		[Action("On_MM_MyClass_Click")]
		void On_MM_MyClass_Click ()
		{
			On_MyClass_HomeWorkList_Click();
		}

		[Action("On_MM_MyClassStudent_Click")]
		void On_MM_MyClassStudent_Click ()
		{
			On_MyClassStudent_HomeWorkList_Click();
		}

		[Action("On_MM_MyCourse_Click")]
		void On_MM_MyCourse_Click ()
		{
			On_MyCourse_Course_Click();
		}

		[Action("On_MM_HomeSchool_Click")]
		void On_MM_HomeSchool_Click ()
		{
			On_HomeSchool_Message_Click();
		}

		[Action("On_MM_HomeSchoolParent_Click")]
		void On_MM_HomeSchoolParent_Click ()
		{
			On_HomeSchoolParent_BiaoXian_Click();
		}

		[Action("On_MM_Personal_Click")]
		void On_MM_Personal_Click ()
		{
			On_Personal_ModifyInformation_Click();
		}

		[Action("On_MM_SyncClass_Click")]
		void On_MM_SyncClass_Click ()
		{
			On_SyncClass_LiveClass_Click();
		}

		private void ShowSubmenu (UIView submenu)
		{
			currShowView.Hidden = true;
			submenu.Hidden = false;
			currShowView = submenu;
		}

		private CourseManageController ctrl_cmc;
		[Action("On_MyCourse_Course_Click")]
		public void On_MyCourse_Course_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_cmc;
			ctrl_cmc.ShowCourseList();
			ShowSubmenu(MM_MyCourse_View);
		}

		[Action("On_MyCourse_Student_Click")]
		public void On_MyCourse_Student_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_cmc;
			ctrl_cmc.ShowStudentList();
			ShowSubmenu(MM_MyCourse_View);
		}

		[Action("On_MyCourse_Class_Click")]
		public void On_MyCourse_Class_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_cmc;
			ctrl_cmc.ShowClassList();
			ShowSubmenu(MM_MyCourse_View);
		}

		[Action("On_MyCourse_StudentApply_Click")]
		public void On_MyCourse_StudentApply_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_cmc;
			ctrl_cmc.ShowCourseApplyList();
			ShowSubmenu(MM_MyCourse_View);
		}

		[Action("On_HomeSchoolParent_HomeWork_Click")]
		public void On_HomeSchoolParent_HomeWork_Click()
		{
			On_MyClass_HomeWorkList_Click();
			ShowSubmenu(MM_HomeSchoolParent_View);
		}

		[Action("On_HomeSchoolParent_StudentCourse_Click")]
		public void On_HomeSchoolParent_StudentCourse_Click()
		{
			On_MyCourse_Course_Click();
			ShowSubmenu(MM_HomeSchoolParent_View);
		}

		[Action("On_HomeSchoolParent_BiaoXian_Click")]
		public void On_HomeSchoolParent_BiaoXian_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mcn;
			ctrl_mcn.ShowClassNoteParentView();
			ShowSubmenu(MM_HomeSchoolParent_View);
		}

		private HomeSchoolController ctrl_hsc;
		[Action("On_HomeSchool_Message_Click")]
		public void On_HomeSchool_Message_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_hsc;
			ctrl_hsc.ShowMessageList();
			ShowSubmenu(MM_HomeScool_View);
		}

		[Action("On_HomeSchool_Parent_Click")]
		public void On_HomeSchool_Parent_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_hsc;
			ctrl_hsc.ShowParentList();
			ShowSubmenu(MM_HomeScool_View);
		}

		private PersonalController ctrl_pc;
		[Action("On_Personal_ModifyInformation_Click")]
		public void On_Personal_ModifyInformation_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_pc;
			ShowSubmenu(MM_Personnal_View);
		}

		private PersonResetPassword ctrl_prp;
		[Action("On_Personal_ResetPass_Click")]
		public void On_Personal_ResetPass_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_prp;
			ShowSubmenu(MM_Personnal_View);
		}

		private MyClassNoteController ctrl_mcn;
		[Action("On_MyClass_Note_Click")]
		public void On_MyClass_Note_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mcn;
			ctrl_mcn.ShowClassNoteList();
			ShowSubmenu(MM_MyClass_View);
		}

		[Action("On_MyClass_NoteItem_Click")]
		public void On_MyClass_NoteItem_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mcn;
			ctrl_mcn.ShowClassNoteItemList();
			ShowSubmenu(MM_MyClass_View);
		}

		[Action("On_MyClass_NoteStat_Click")]
		public void On_MyClass_NoteStat_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mcn;
			ctrl_mcn.ShowClassNoteStat();
			ShowSubmenu(MM_MyClass_View);
		}

		private MyClassController ctrl_mc;
		[Action("On_MyClass_HomeWorkList_Click")]
		public void On_MyClass_HomeWorkList_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mc;
			ctrl_mc.ShowHistory();
			ShowSubmenu(MM_MyClass_View);
		}

		[Action("On_MyClass_NewHomeWork_Click")]
		public void On_MyClass_NewHomeWork_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mc;
			ctrl_mc.ShowNewHomeWork();
			ShowSubmenu(MM_MyClass_View);
		}

		[Action("On_MyClass_SetHomeWork_Click")]
		public void On_MyClass_SetHomeWork_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_mc;
			ctrl_mc.ShowCommitHomeWork();
			ShowSubmenu(MM_MyClass_View);
		}

		[Action("On_MyClassStudent_HomeWorkList_Click")]
		public void On_MyClassStudent_HomeWorkList_Click()
		{
			On_MyClass_HomeWorkList_Click();
			ShowSubmenu(MM_MyClassStudent_View);
		}

		[Action("On_MyClassStudent_CourseList_Click")]
		public void On_MyClassStudent_CourseList_Click()
		{
			On_MyCourse_Course_Click();
			ShowSubmenu(MM_MyClassStudent_View);
		}

		[Action("On_MyClassStudent_ClassmateList_Click")]
		public void On_MyClassStudent_ClassmateList_Click()
		{
			On_MyCourse_Student_Click();
			ShowSubmenu(MM_MyClassStudent_View);
		}

		[Action("On_MyClassStudent_Message_Click")]
		public void On_MyClassStudent_Message_Click()
		{
			On_HomeSchool_Message_Click();
			ShowSubmenu(MM_MyClassStudent_View);
		}

		private VideoList ctrl_video;
		[Action("On_SyncClass_LiveClass_Click")]
		public void On_SyncClass_LiveClass_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_video;
			ShowSubmenu(MM_SyncClass_View);
		}

		[Action("On_SyncClass_VODClass_Click")]
		public void On_SyncClass_VODClass_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_video;
			ShowSubmenu(MM_SyncClass_View);
		}

		[Action("On_SyncClass_OpenClass_Click")]
		public void On_SyncClass_OpenClass_Click()
		{
			AppDelegate.split.DetailViewController = ctrl_video;
			ShowSubmenu(MM_SyncClass_View);
		}

		public LeftTabController () : base ("LeftTabController", null)
		{
		}
		
		public override void DidReceiveMemoryWarning ()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning ();
			
			// Release any cached data, images, etc that aren't in use.
		}
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// Perform any additional setup after loading the view, typically from a nib.
			AppDelegate.split.DetailViewController = this.ctrl_cmc = new CourseManageController();
			AppDelegate.split.DetailViewController = this.ctrl_hsc = new HomeSchoolController();
			AppDelegate.split.DetailViewController = this.ctrl_mc = new MyClassController();
			AppDelegate.split.DetailViewController = this.ctrl_mcn = new MyClassNoteController();
			AppDelegate.split.DetailViewController = this.ctrl_pc = new PersonalController();
			AppDelegate.split.DetailViewController = this.ctrl_prp = new PersonResetPassword();
			AppDelegate.split.DetailViewController = this.ctrl_video = new VideoList();

			currShowView = MM_MyClass_View;
			if (AppDelegate.loginuser is M_Teacher) {

				MMGroup_Teacher_View.Hidden = false;
				ShowSubmenu(MM_MyClass_View);

			} else if (AppDelegate.loginuser is M_Parent) {
				MMGroup_Parent_View.Hidden = false;
				ShowSubmenu(MM_HomeSchoolParent_View);
			} else {
				MMGroup_Student_View.Hidden = false;
				ShowSubmenu(MM_MyClassStudent_View);
			}
		}
		
		public override void ViewDidUnload ()
		{
			base.ViewDidUnload ();
			
			// Clear any references to subviews of the main view in order to
			// allow the Garbage Collector to collect them sooner.
			//
			// e.g. myOutlet.Dispose (); myOutlet = null;
			
			ReleaseDesignerOutlets ();
		}
		
		public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
		{
			// Return true for supported orientations
			return true;
		}
	}
}

